package cn.dxh.stagefinal.service.impl;

import cn.dxh.stagefinal.bean.Company;
import cn.dxh.stagefinal.bean.Department;
import cn.dxh.stagefinal.bean.Employee;
import cn.dxh.stagefinal.dao.DepartmentDao;
import cn.dxh.stagefinal.dao.EmployeeDao;
import cn.dxh.stagefinal.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * IntelliJ IDEA -> stagefinal
 * 2019/12/10 9:41
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
@Service
public class DepartmentServieImpl implements DepartmentService {
    @Autowired
    private DepartmentDao departmentDao;
    @Autowired
    private EmployeeDao employeeDao;

    @Transactional
    @Override
    public int insertDepartment(Department department) {
        return departmentDao.insertDepartment(department);
    }

    @Override
    public List<Department> findDepartments() {
        return departmentDao.findDepartments();
    }

    @Transactional
    @Override
    public int deleteDepartmentByDid(Integer dId) {
        int empCount = employeeDao.findEmpByDid(dId);
        if (empCount > 0 ){
            return  -1 ;
        }
        return departmentDao.deleteDepartmentByDid(dId);
    }

    @Override
    public Department findDepartmentByDid(Integer dId) {
        return departmentDao.findDepartmentByDid(dId);
    }

    @Override
    public int updatedepartment(Department department) {
        return departmentDao.updatedepartment(department);
    }
}
